/**
 * 
 */
package com.heer.RD.auth;

import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authorization.IAuthorizationStrategy;
import org.apache.wicket.authorization.strategies.CompoundAuthorizationStrategy;

import com.heer.RD.projecthour.page.LoginPage;

/**
 * @author ZhaoZehui
 *
 */
public class HeerAuthorizationStrategy extends CompoundAuthorizationStrategy {

	@SuppressWarnings("unchecked")
    private static final class ProtectedComponentChecker implements IAuthorizationStrategy {
        
    	public boolean isInstantiationAuthorized(final Class componentClass) {
            if(AuthenticatedIF.class.isAssignableFrom(componentClass)
                && !((HeerSession)HeerSession.get()).isSignIn()) {
            	//认证无效，跳转到登录页
                throw new RestartResponseAtInterceptPageException(LoginPage.class);
            }
            return true;
        }

        public boolean isActionAuthorized(final Component component, final Action action) {
            return true;
        }
    }
	
	public HeerAuthorizationStrategy() {
	   add(new ProtectedComponentChecker());
	}
	
}
